package com.softeem.springcloud.service;

import com.softeem.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: springcloud
 * @author: zcp_will
 * @create: 2020-09-19 14:35
 * @description
 **/
//服务降级的工厂类，对整个类进行服务降级
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept queryById(int id) {
                return new Dept()
                        .setDeptno(id)
                        .setDname("id=>"+id+"没有对象信息，客户端提供了降级的信息，这个服务现在已经被关闭")
                        .setDb_source("没有数据");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}
